//
//  InvitePeopleView.m
//  Cat
//
//  Created by 卢仕彤 on 2019/3/15.
//  Copyright © 2019年 lushitong. All rights reserved.
//

#import "InvitePeopleView.h"
#import "FLHeadView.h"
#import "InviteModel.h"
#import "QKShareLiveSheetManager.h"

@interface InvitePeopleView()

@property (nonatomic, strong) UIView *operView;
@property (nonatomic, strong) FLHeadView *headView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *fansNumberLabel;
@property (nonatomic, strong) UILabel *messageLabel;
@property (nonatomic, strong) UIView *topLineView;
@property (nonatomic, strong) UIView *secLineView;
@property (nonatomic, strong) UIButton *cannButton;
@property (nonatomic, strong) UIButton *sureButton;

@end

@implementation InvitePeopleView

- (void)setModel:(InviteModel *)model {
    _model = model;
    [self.headView setImageUrl:[NSURL URLWithString:model.avator] size:CGSizeMake(kQKFitModuleDecimal(40.0), kQKFitModuleDecimal(40.0)) cornerRadius:kQKFitModuleDecimal(20.0)];
    self.nameLabel.text = model.nickName;
    self.fansNumberLabel.text = [NSString stringWithFormat:@"粉丝数%@",model.fansNum];
    self.messageLabel.text = [NSString stringWithFormat:@"确认选择%@为你的邀请人",model.nickName];
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.userInteractionEnabled = YES;
        [self loadAllSubViews];
    }
    return self;
}

- (void)loadAllSubViews {
    [self addSubview:self.operView];
    
    [self.operView addSubviews:@[self.headView,
                                 self.nameLabel,
                                 self.fansNumberLabel,
                                 self.messageLabel,
                                 self.topLineView,
                                 self.secLineView,
                                 self.cannButton,
                                 self.sureButton]];
    
    [self.operView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(CGSizeMake(ScreenWidth - 2* kQKFitModuleDecimal(61), kQKFitModuleDecimal(189)));
        make.center.equalTo(self);
    }];
    
    
    [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(kQKFitModuleDecimal(40.0), kQKFitModuleDecimal(40.0)));
        make.top.equalTo(self.operView.mas_top).offset(kQKFitModuleDecimal(20.0));
        make.centerX.equalTo(self.operView.mas_centerX);
    }];
    
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.operView.mas_centerX);
        make.top.equalTo(self.headView.mas_bottom).offset(kQKFitModuleDecimal(8.0));
    }];
    
    [self.fansNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.operView.mas_centerX);
        make.top.equalTo(self.nameLabel.mas_bottom);
    }];
    
    [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.operView.mas_centerX);
        make.top.equalTo(self.fansNumberLabel.mas_bottom).offset(kQKFitModuleDecimal(13.0));
    }];
    
    [self.topLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(kQKFitModuleDecimal(1.0)));
        make.left.and.right.equalTo(self.operView);
        make.bottom.equalTo(self.operView.mas_bottom).offset(-kQKFitModuleDecimal(36));
    }];
    
    [self.secLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topLineView.mas_bottom);
        make.bottom.equalTo(self.operView.mas_bottom);
        make.width.equalTo(@(kQKFitModuleDecimal(1.0)));
        make.centerX.equalTo(self.operView.mas_centerX);
    }];
    
    [self.cannButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.operView.bottom);
        make.top.equalTo(self.topLineView.mas_bottom);
        make.left.equalTo(self.operView.mas_left);
        make.right.equalTo(self.secLineView.mas_left);
    }];
    
    [self.sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.operView.bottom);
        make.top.equalTo(self.topLineView.mas_bottom);
        make.left.equalTo(self.secLineView.mas_right);
        make.right.equalTo(self.operView.mas_right);
    }];
}

#pragma mark action

- (void)cannButtonAction {
    [QKShareLiveSheetManager dissMissInvite];
}

- (void)sureButtonAction {
    [QKShareLiveSheetManager dissMissInvite];
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickInvitePeopleViewWith:)]) {
        [self.delegate clickInvitePeopleViewWith:self.model];
    }
}

#pragma mark lazy init

- (UIView *)operView {
    if (!_operView) {
        _operView = [[UIView alloc] init];
        _operView.backgroundColor = [UIColor whiteColor];
        _operView.userInteractionEnabled = YES;
    }
    return _operView;
}


- (FLHeadView *)headView {
    if (!_headView) {
        _headView = [[FLHeadView alloc] init];
    }
    return _headView;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [UILabel labelWithFont:[UIFont boldSystemFontOfSize:kQKFitFont(14)] textColor:COLOR_WITH_HEX(0x4C4947)];
    }
    return _nameLabel;
}

- (UILabel *)fansNumberLabel {
    if (!_fansNumberLabel) {
        _fansNumberLabel = [UILabel labelWithFont:[UIFont systemFontOfSize:kQKFitFont(10)] textColor:COLOR_WITH_HEX(0xCDC7C4)];
    }
    return _fansNumberLabel;
}

- (UILabel *)messageLabel {
    if (!_messageLabel) {
        _messageLabel = [UILabel labelWithFont:[UIFont systemFontOfSize:kQKFitFont(12)] textColor:COLOR_WITH_HEX(0x4C4947)];
    }
    return _messageLabel;
}

- (UIView *)topLineView {
    if (!_topLineView) {
        _topLineView = [[UIView alloc] init];
        _topLineView.backgroundColor = COLOR_WITH_HEX(0xEEEBEB);
    }
    return _topLineView;
}

- (UIView *)secLineView {
    if (!_secLineView) {
        _secLineView = [[UIView alloc] init];
        _secLineView.backgroundColor = COLOR_WITH_HEX(0xEEEBEB);
    }
    return _secLineView;
}

- (UIButton *)cannButton {
    if (!_cannButton) {
        _cannButton = [UIButton buttonWithTitle:@"取消" color:COLOR_WITH_HEX(0xCDC7C4) font:[UIFont systemFontOfSize:14]];
        [_cannButton addTarget:self action:@selector(cannButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cannButton;
}

- (UIButton *)sureButton {
    if (!_sureButton) {
        _sureButton = [UIButton buttonWithTitle:@"确定" color:COLOR_WITH_HEX(0xFFC236) font:[UIFont systemFontOfSize:14]];
        [_sureButton addTarget:self action:@selector(sureButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _sureButton;
}

@end

